package typistcal.executor;

import static org.junit.Assert.*;

import org.junit.Test;

//@author A0105493H
public class ExecutorTest {

	public static void testReplaceWithTime() {
		int indexNo = 0;
		int length = 3;
		String originalString = "this is a test from 2 January 2015 00:00 to 4 March 2015 23:59 Incomplete";
		String replacementString = "3 March 2015";
		String splitKeyword = "from";
		/*
		 * Following test cases use equivalence partitioning if
		 * replacementString.length() equals to length, the result is the
		 * updated version if not, the result is the original one
		 */

		// this is a test case where length equals to replacementString.length()
		assertEquals(
				"this is a test from 3 March 2015 00:00 to 4 March 2015 23:59 Incomplete",
				Executor.replaceWithTime(indexNo, length, originalString,
						replacementString, splitKeyword));

		// The following two test cases where length not equals to
		// replaceString.length()
		length = 4;
		assertEquals(
				"this is a test from 2 January 2015 00:00 to 4 March 2015 23:59 Incomplete",
				Executor.replaceWithTime(indexNo, length, originalString,
						replacementString, splitKeyword));

		replacementString = "3 March";
		assertEquals(
				"this is a test from 2 January 2015 00:00 to 4 March 2015 23:59 Incomplete",
				Executor.replaceWithTime(indexNo, length, originalString,
						replacementString, splitKeyword));
	}

	public void testConvertToStandard() {
		/*
		 * Following test cases use equivalence partitioning There are 3
		 * possible event types, which are todo, deadline and schedule.
		 */
		String targetTodo = "test1 Incomplete";
		String targetDeadline = "test2 by 12 April 2014 8:00 Incomplete";
		String targetSchedule = "test3 from 12 April 2014 7:00 to 12 April 2014 8:00 Incomplete";
		assertEquals(Executor.convertToStandard(targetTodo, "todo"),
				"\n    Event label:       test1\n    Current status:  Incomplete");
		assertEquals(
				Executor.convertToStandard(targetDeadline, "deadline"),
				"\n    Event label:       test2\n    Deadline:          12 April 2014 8:00\n    Current status:  Incomplete");
		assertEquals(
				Executor.convertToStandard(targetSchedule, "schedule"),
				"\n    Event label:       test3\n    Start from:        12 April 2014 7:00\n    End by:             12 April 2014 8:00\n    Current status:  Incomplete");

	}

	public void testFindLineNumber() {

		String line1 = "1 test1";
		assertEquals(Executor.findLineNumber(line1), 1);

		String line2 = "23 This is a test to find line number";
		assertEquals(Executor.findLineNumber(line2), 23);

		String line3 = "155 This sentence contains a number. i.Executor. 34";
		assertEquals(Executor.findLineNumber(line3), 155);

	}

	public void testIncreaseTimes() {
		/*
		 * Following test cases use equivalence partitioning and boundary cases
		 * testing The return value of increaseTimes() method is an array So we
		 * test each component one by one
		 */

		String s = "schedule";
		String t = "todo";
		String d = "deadline";
		int todoDeleteTimes = 3;
		int scheduleDeleteTimes = 0;
		int deadlineDeleteTimes = 199;
		String todoResult = new Integer(todoDeleteTimes + 1).toString();
		String scheduleResult = new Integer(scheduleDeleteTimes + 1).toString();
		String deadlineResult = new Integer(deadlineDeleteTimes + 1).toString();
		/*
		 * This is a test for schedule task We use boundary case where
		 * scheduleDeleteTimes = 0
		 */
		String result = Executor.increaseTimes(s, scheduleDeleteTimes,
				deadlineDeleteTimes, todoDeleteTimes)[0];
		assertEquals(result, s);

		result = Executor.increaseTimes(s, scheduleDeleteTimes,
				deadlineDeleteTimes, todoDeleteTimes)[1];
		assertEquals(result, scheduleResult);
		/*
		 * This a test for todo task we use normal number as todoDeleteTimes
		 */

		result = Executor.increaseTimes(t, scheduleDeleteTimes,
				deadlineDeleteTimes, todoDeleteTimes)[0];
		assertEquals(result, t);

		result = Executor.increaseTimes(t, scheduleDeleteTimes,
				deadlineDeleteTimes, todoDeleteTimes)[1];
		assertEquals(result, todoResult);
		/*
		 * This is a test for deadline task We test a relatively big number as
		 * deadlineDeleteTimes
		 */

		result = Executor.increaseTimes(d, scheduleDeleteTimes,
				deadlineDeleteTimes, todoDeleteTimes)[0];
		assertEquals(result, d);

		result = Executor.increaseTimes(d, scheduleDeleteTimes,
				deadlineDeleteTimes, todoDeleteTimes)[1];
		assertEquals(result, deadlineResult);

	}

	@Test
	public void test() {

		assertEquals(true, true);
	}

	public void testConvertToString() {
		/*
		 * The following test cases use boundary cases tests
		 */

		/*
		 * This test tests the normal number
		 */
		int[] lineNumber1 = { 1, 3, 0, 199, 897, 14 };
		String expectedResult1 = "1 3 0 199 897 14 ";
		String testResult1 = Utility.convertIntArrayToString(lineNumber1);
		assertEquals(expectedResult1, testResult1);

		/*
		 * This test tests relatively large numbers which may cause bugs
		 */
		int[] lineNumber2 = { 99999, 100000, 357, 0, 88 };
		String expectedResult2 = "99999 100000 357 0 88 ";
		String testResult2 = Utility.convertIntArrayToString(lineNumber2);
		assertEquals(expectedResult2, testResult2);

		/*
		 * This test tests what happen when negative numbers are involved
		 */
		int[] lineNumber3 = { -99999, -100000, -357, 0, -88 };
		String expectedResult3 = "-99999 -100000 -357 0 -88 ";
		String testResult3 = Utility.convertIntArrayToString(lineNumber3);
		assertEquals(expectedResult3, testResult3);

	}

	public void testFindType() {
		/*
		 * The following tests use equivalence partitioning. There are 3 types
		 * of test cases which are schedule, todo, and deadline
		 */
		String schedule = "test1 scheduledFile.txt";
		String todo = "test2 todoFile.txt";
		String deadline = "test3 deadlineFile.txt";

		String scheduleResult = "schedule";
		String deadlineResult = "deadline";
		String todoResult = "todo";

		String scheduleTest = Executor.findType(schedule);
		String todoTest = Executor.findType(todo);
		String deadlineTest = Executor.findType(deadline);
		assertEquals(scheduleTest, scheduleResult);
		assertEquals(deadlineTest, deadlineResult);
		assertEquals(todoTest, todoResult);

	}

}
